package edu.spec.wechat.web;

import edu.spec.pms.model.student.Student;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by MadFrog on 2016/10/17.
 * 1.wechat access_token中控器
 * 2.配置各种微信基本常量
 * 通过quartz每隔6000秒获取一次access_token
 */
public class WechatContext {
    private String appID;
    private String appsecrect;
    private String baseurl;
    private String basetoken;
    private static String accessToken;
    private static String jsApiTicket;
    private static Map<String, Student> wechatUserMap = new HashMap<String, Student>();
    private static WechatContext wc;

    private WechatContext(){}

    public static WechatContext getInstance(){
        if (wc==null){
            wc = new WechatContext();
        }
        return wc;
    }

    public String getAppID() {
        return appID;
    }

    public void setAppID(String appID) {
        this.appID = appID;
    }

    public String getAppsecrect() {
        return appsecrect;
    }

    public void setAppsecrect(String appsecrect) {
        this.appsecrect = appsecrect;
    }

    public String getBaseurl() {
        return baseurl;
    }

    public void setBaseurl(String baseurl) {
        this.baseurl = baseurl;
    }

    public String getBasetoken() {
        return basetoken;
    }

    public void setBasetoken(String basetoken) {
        this.basetoken = basetoken;
    }

    public static String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        WechatContext.accessToken = accessToken;
    }

    public static String getJsApiTicket() {
        return jsApiTicket;
    }

    public static void setJsApiTicket(String jsApiTicket) {
        WechatContext.jsApiTicket = jsApiTicket;
    }

    public void addWechatUser(String openId, Student wechatUser){
        wechatUserMap.put(openId, wechatUser);
    }

    public void removeWechatUser(String openId){
        wechatUserMap.remove(openId);
    }

    public Student getWechatUser(String openId) {
        return wechatUserMap.get(openId);
    }

    public WechatContext getWc() {
        return wc;
    }

    public void setWc(WechatContext wc) {
        WechatContext.wc = wc;
    }
}
